﻿<UserControl
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:controls="clr-namespace:MyAnimelistRecommender.Controls"
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
             xmlns:helper="clr-namespace:MyAnimelistRecommender.Helper"
            xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
            x:Class="MyAnimelistRecommender.Controls.TabControls.Recommendations"
             mc:Ignorable="d"
             d:DesignHeight="300" d:DesignWidth="800" d:DataContext="{d:DesignData /SampleData/RecommendationModelSampleData3.xaml}" Background="White">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/PresentationFramework.Aero, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35,ProcessorArchitecture=MSIL;component/themes/aero.normalcolor.xaml" />
                <ResourceDictionary Source="/Resource/Style.xaml" />
                <ResourceDictionary Source="/Resource/Brush.xaml" />
                <ResourceDictionary Source="/Resource/Converter.xaml" />
            </ResourceDictionary.MergedDictionaries>

            <DataTemplate x:Key="AnimeRecommendation">
                <StackPanel Orientation="Horizontal" Margin="0 2.5">
                    <VisualStateManager.VisualStateGroups>
                        <VisualStateGroup x:Name="LanguageStateGroup">
                            <VisualState x:Name="IsEnglish">
                                <Storyboard FillBehavior="HoldEnd">
                                    <DoubleAnimation Storyboard.TargetProperty="Opacity" Duration="00:00:01" To="1" Storyboard.TargetName="image">
                                        <DoubleAnimation.EasingFunction>
                                            <ElasticEase Oscillations="30" EasingMode="EaseIn"  />
                                        </DoubleAnimation.EasingFunction>
                                    </DoubleAnimation>
                                </Storyboard>
                            </VisualState>
                            <VisualState x:Name="IsNotEnglish">
                                <Storyboard FillBehavior="HoldEnd">
                                    <DoubleAnimation Storyboard.TargetProperty="Opacity" Duration="00:00:01" To="0.12" Storyboard.TargetName="image">
                                        <DoubleAnimation.EasingFunction>
                                            <QuarticEase EasingMode="EaseIn"  />
                                        </DoubleAnimation.EasingFunction>
                                    </DoubleAnimation>
                                </Storyboard>
                            </VisualState>
                        </VisualStateGroup>
                    </VisualStateManager.VisualStateGroups>
                    <Grid Height="Auto">
                        <controls:CachedImage ImageUrl="{Binding Image}" Height="80" Width="60" Stretch="UniformToFill" HorizontalAlignment="Left" Margin="0" />

                        <TextBlock TextWrapping="Wrap" HorizontalAlignment="Right" VerticalAlignment="Top" FontWeight="ExtraBold" FontSize="{Binding FontSize, ElementName=textBlock}" Width="Auto" d:LayoutOverrides="VerticalAlignment" Padding="3,0,0,3"><TextBlock.Effect>
                            <BlurEffect />
                        </TextBlock.Effect><Run Text="#"/><Run Text="{Binding Place, Mode=OneWay}"/></TextBlock>
                        <TextBlock TextWrapping="Wrap" HorizontalAlignment="Right" VerticalAlignment="Top" FontWeight="ExtraBold" FontSize="{Binding FontSize, ElementName=textBlock}" Width="Auto" d:LayoutOverrides="VerticalAlignment" Padding="3,0,0,3"><TextBlock.Effect>
                            <BlurEffect />
                        </TextBlock.Effect><Run Text="#"/><Run Text="{Binding Place, Mode=OneWay}"/></TextBlock>
                        <TextBlock Foreground="White" TextWrapping="Wrap" HorizontalAlignment="Right" VerticalAlignment="Top" FontWeight="ExtraBold" FontSize="{Binding FontSize, ElementName=textBlock}" Width="Auto" d:LayoutOverrides="VerticalAlignment" Padding="3,0,0,3"><Run Text="#"/><Run Text="{Binding Place, Mode=OneWay}"/></TextBlock>
                    </Grid>
                    <StackPanel Margin="10 0 0 0" VerticalAlignment="Center">
                        <StackPanel Height="15.96" Orientation="Horizontal">
                            <TextBlock x:Name="textBlock" HorizontalAlignment="Left" Cursor="Hand" Text="{Binding Name}" Foreground="Blue" MouseUp="TextBlock_MouseUp" VerticalAlignment="Top" Margin="0" />
                            <Image x:Name="image" HorizontalAlignment="Left" Opacity="0" Width="Auto" Height="15.96" Source="/MyAnimelistRecommender;component/Media/en.gif" Margin="10,0,0,0">
                                <i:Interaction.Behaviors>
                                    <ei:DataStateBehavior TrueState="IsEnglish" FalseState="IsNotEnglish" Binding="{Binding IsEnglish}" Value="True"/>
                                </i:Interaction.Behaviors>
                            </Image>
                        </StackPanel>
                        <Border BorderThickness="1" Margin="0" Height="Auto" Width="Auto" HorizontalAlignment="Left" BorderBrush="{x:Null}">
                            <Grid Height="Auto" Margin="0">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="0.334*"/>
                                    <RowDefinition Height="0.666*"/>
                                </Grid.RowDefinitions>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto" MinWidth="30"/>
                                    <ColumnDefinition Width="Auto" MinWidth="60"/>
                                    <ColumnDefinition Width="Auto" MinWidth="60"/>
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>
                                <TextBlock x:Name="textBlock1" d:LayoutOverrides="Height" Grid.RowSpan="1" Text="All" HorizontalAlignment="Center" Margin="0,0,0,2"/>
                                <TextBlock Grid.RowSpan="1" d:LayoutOverrides="Height" Grid.Row="1" HorizontalAlignment="Center" Text="{Binding Votes}" Margin="0,2,0,0" FontWeight="{Binding Text, Converter={StaticResource SortingStateToFontWeightConverter}, ElementName=textBlock1}"/>
                                <Border BorderBrush="{DynamicResource {x:Static SystemColors.ActiveBorderBrushKey}}" BorderThickness="0,0,1,0" Grid.ColumnSpan="1" Margin="0" Grid.RowSpan="2" Padding="0"/>
                                <TextBlock x:Name="textBlock2" Grid.RowSpan="1" Text="Scored" HorizontalAlignment="Center" d:LayoutOverrides="Height" Grid.Column="1"/>
                                <TextBlock Grid.RowSpan="1" Grid.Row="1" HorizontalAlignment="Center" Text="{Binding CalcedVotes}" Margin="0,2,0,0" d:LayoutOverrides="Height" Grid.Column="1" FontWeight="{Binding Text, Converter={StaticResource SortingStateToFontWeightConverter}, ElementName=textBlock2}"/>
                                <Border BorderBrush="{DynamicResource {x:Static SystemColors.ActiveBorderBrushKey}}" BorderThickness="0,0,1,0" Grid.ColumnSpan="1" Margin="0" Grid.RowSpan="2" Grid.Column="1"/>
                                <TextBlock x:Name="textBlock3" Grid.RowSpan="1" Text="Sources" HorizontalAlignment="Center" d:LayoutOverrides="Height, GridBox" Grid.Column="2"/>
                                <TextBlock Grid.RowSpan="1" Grid.Row="1" HorizontalAlignment="Center" Text="{Binding Sources}" Margin="0,2,0,0" d:LayoutOverrides="Height, GridBox" Grid.Column="2" FontWeight="{Binding Text, Converter={StaticResource SortingStateToFontWeightConverter}, ElementName=textBlock3}"/>
                                <Border BorderBrush="{DynamicResource {x:Static SystemColors.ActiveBorderBrushKey}}" BorderThickness="0,0,1,0" Grid.ColumnSpan="1" Margin="0" Grid.RowSpan="2" Grid.Column="2"/>
                                <TextBlock Grid.RowSpan="1" Text="Most Recommendations" HorizontalAlignment="Center" Grid.Column="3" d:LayoutOverrides="Height, GridBox" Margin="5,0"/>
                                <Border BorderBrush="{DynamicResource {x:Static SystemColors.ActiveBorderBrushKey}}" BorderThickness="0,0,0,1" Grid.ColumnSpan="21" Margin="0"/>
                                <ComboBox Style="{DynamicResource NoHoverComboBoxStyle}" Grid.ColumnSpan="3" Margin="0" d:LayoutOverrides="Height" Grid.Row="1" Grid.Column="3" ItemsSource="{Binding RecNamesAndScore}" SelectedIndex="0" Background="{x:Null}" BorderBrush="{x:Null}">
                                    <ComboBox.ItemTemplate>
                                        <DataTemplate>
                                            <TextBlock HorizontalAlignment="Center"><Run Text="{Binding Value, Mode=OneWay}"/><Run Text=" "/><Run Text=" "/><Run Text=" "/><Run Text="@"/><Run Text=" "/><Run Text=" "/><Run Text=" "/><Run Text="{Binding Key, Mode=OneWay}"/></TextBlock>
                                        </DataTemplate>
                                    </ComboBox.ItemTemplate>
                                </ComboBox>
                            </Grid>
                        </Border>
                        <StackPanel Height="Auto">
                            <TextBlock HorizontalAlignment="Left" TextWrapping="Wrap"><Run Text="Genres:"/><Run Text=" "/><Run Text="{Binding Genres, Converter={StaticResource JoinListToStringConverter}}"/></TextBlock>
                            <TextBlock HorizontalAlignment="Stretch" TextWrapping="Wrap" VerticalAlignment="Stretch"><Run Text="Rank: #"/><Run Text="{Binding Rank}"/><Run Text=" "/><Span/><Run Text=" "/><Run Text="Score:"/><Run Text=" "/><Run Text="{Binding MemberScore}"/></TextBlock>
                        </StackPanel>
                        <!--<Grid Height="Auto">
                    	<TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" d:LayoutOverrides="Height">
                            <Run Text="Sprachen:"/>
                            <Run Text="{Binding LangString, Mode=OneWay}"/>
                        </TextBlock>
                    </Grid>-->
                    </StackPanel>
                </StackPanel>
            </DataTemplate>
            <Style x:Key="AnimeRecommendationStyle" TargetType="{x:Type ListBoxItem}">
                <Setter Property="Background" Value="Transparent"/>
                <Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
                <Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
                <Setter Property="Padding" Value="2,0,0,0"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type ListBoxItem}">
                            <Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="true">
                                <VisualStateManager.VisualStateGroups>
                                    <VisualStateGroup x:Name="CommonStates">
                                        <VisualState x:Name="Normal"/>
                                        <VisualState x:Name="MouseOver"/>
                                        <VisualState x:Name="Disabled"/>
                                    </VisualStateGroup>
                                    <VisualStateGroup x:Name="SelectionStates">
                                        <VisualState x:Name="Unselected"/>
                                        <VisualState x:Name="Selected"/>
                                        <VisualState x:Name="SelectedUnfocused"/>
                                    </VisualStateGroup>
                                </VisualStateManager.VisualStateGroups>
                                <Grid Background="Transparent">
                                    <Grid.ContextMenu>
                                        <ContextMenu>
                                            <MenuItem Header="Backlist" Click="MenuItem_Click" />
                                        </ContextMenu>
                                    </Grid.ContextMenu>
                                    <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                                </Grid>
                            </Border>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsSelected" Value="true">
                                    <Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
                                    <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/>
                                </Trigger>
                                <MultiTrigger>
                                    <MultiTrigger.Conditions>
                                        <Condition Property="IsSelected" Value="true"/>
                                        <Condition Property="Selector.IsSelectionActive" Value="false"/>
                                    </MultiTrigger.Conditions>
                                    <Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
                                    <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
                                </MultiTrigger>
                                <Trigger Property="IsEnabled" Value="false">
                                    <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </ResourceDictionary>
    </UserControl.Resources>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="auto" />
        </Grid.RowDefinitions>
        <ListBox BorderThickness="0" Background="{x:Null}" x:Name="lbNormal" ItemTemplate="{DynamicResource AnimeRecommendation}" ItemsSource="{Binding Recommendations}" Margin="0" SelectedItem="{Binding SelectedRecommendation, Mode=TwoWay}" SelectionChanged="Listbox_SelectionChanged" Grid.Row="0" Grid.ColumnSpan="2" BorderBrush="{x:Null}" SelectionMode="Extended" ItemContainerStyle="{DynamicResource AnimeRecommendationStyle}" >
            <ListBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <VirtualizingStackPanel helper:PixelBasedScrollingBehavior.IsEnabled="True"/>
                </ItemsPanelTemplate>
            </ListBox.ItemsPanel>
        </ListBox>
        <!--<ListBox Name="lbWeighted" ScrollViewer.ScrollChanged="lbWeighted_ScrollChanged" ItemTemplate="{DynamicResource DataTemplate}" ItemsSource="{Binding SRecs}" Grid.Column="1" Margin="0" SelectedItem="{Binding SelectedRecommendation,Mode=TwoWay}" SelectionChanged="Listbox_SelectionChanged" Grid.Row="1" /> -->
        <ProgressBar Grid.Row="1" Maximum="{Binding AnimeCount}" Value="{Binding AnimeProgress}" Grid.ColumnSpan="2" />

        <StackPanel Grid.Row="1" Grid.ColumnSpan="2" Orientation="Horizontal" HorizontalAlignment="Center" d:LayoutOverrides="GridBox">
            <TextBlock Text="{Binding AnimeProgress}" />
            <TextBlock Text=" / " />
            <TextBlock Text="{Binding AnimeCount}" />
        </StackPanel>
    </Grid>
</UserControl>